package com.xak.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xak.dao.StudentMapper;
import com.xak.pojo.entity.Student;
import com.xak.pojo.vo.StudentVo;
import com.xak.service.StudentService;
import com.xak.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: springboot0412
 * @description:
 * @author: 肖安康
 * @create: 2023-04-12 19:42
 **/
@RestController
@Api(value = "学生操作API")
public class StudentController {
    @Autowired
    StudentService studentService;

    @ApiOperation(value = "查询学生信息")
    @PostMapping("find/{current}/{pageSize}")
    public Result find(
            @ApiParam(value = "当前页面",name ="current",required = true,defaultValue = "1")
                @PathVariable Integer current,
            @ApiParam(value = "每页条数",name ="pageSize",required = true,defaultValue = "3")
                @PathVariable Integer pageSize,
            @RequestBody StudentVo studentVo
    ){
        return studentService.findByPage(current,pageSize,studentVo);
    }

    @Autowired
    private StudentMapper studentMapper;

    @DeleteMapping("deleteById/{id}")
    @ApiOperation(value = "根据id删除学生")
    public int deleteById(@PathVariable Integer id){
        return studentMapper.deleteById(id);
    }

    @PostMapping("insert")
    @ApiOperation(value = "添加学生")
    public int insert(@RequestBody Student student){
        return studentMapper.insert(student);
    }

    @PostMapping("/updateUser")
    @ApiOperation(value = "修改学生信息")
    public Result updateUser(@RequestBody Student student){
        Student student1=new Student();
        student1.setSname(student.getSname());
        student1.setSage(student.getSage());
        student1.setStuno(student.getStuno());
        student1.setCid(student.getCid());
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        wrapper.eq("id",student.getId());
        return new Result(200,"修改成功",studentMapper.update(student1,wrapper));

    }
    @ApiOperation(value = "根据id查询学生信息")
    @PostMapping("find/{id}")
    public Student findId(@PathVariable Integer id){
        return studentMapper.selectById(id);
    }
}
